package list.ittest.Test.B_Controller;

import list.ittest.Test.C_Service.StudentService;
import list.ittest.Test.E_Domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public abstract class DemoStudentController {
    StudentService studentService = new StudentService();
    public void start() {
        Scanner sc = new Scanner(System.in);
        ol:
        while (true) {
            System.out.println("--------欢迎来到学生管理系统--------");
            System.out.println("请输入您的选择： 1.添加学生\t 2.删除学生\t 3.修改学生\t4.查找学生\t5.退出");
            String choice = sc.next();
            switch (choice) {
                case "1":
                    //System.out.println("添加学生");
                    addStudent();
                    break;
                case "2":
                    //System.out.println("删除学生");
                    deleteStudent();
                    break;
                case "3":
                    //System.out.println("修改学生");
                    updateStudent();
                    break;
                case "4":
                    //System.out.println("查找学生");
                    findAllStudent();
                    break;
                case "5":
                    System.out.println("感谢使用学生管理系统！下次再见");
                    break ol;
                default:
                    System.out.println("你输入的有问题，请重新再试");
                    break;
            }
        }
    }
    //修改学生
    public void updateStudent() {
        Scanner sc =new Scanner(System.in);
        System.out.println("请输入你想要修改的学生学号：");
        String id = sc.next();
        boolean flag = studentService.cheakId(id);
        if(flag == true){
            System.out.println("不好意思，该学号学生不存在");
            return;
        }
        System.out.println("请输入想要修改的学生姓名");
        String name = sc.next();
        System.out.println("请输入想要修改的学生年龄");
        int age = sc.nextInt();
        System.out.println("请输入想要修改的学生生日");
        String birthday = sc.next();
        Student s =new Student();
        s.setId(id);
        s.setName(name);
        s.setAge(age);
        s.setBirthday(birthday);
        studentService.updateStudent(s);
        System.out.println("修改成功");

    }

    //删除学生
   public void deleteStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入想要删除的id：");
        String id =sc.nextLine();
        boolean flag = studentService.deleteStudent(id);
        if(flag == false){
            System.out.println("删除失败，查无此人");
        }else{
            System.out.println("删除成功！");
        }
    }

    //查找学生`
    public void findAllStudent() {
       // StudentService studentService = new StudentService();
        ArrayList<Student> list =studentService.findAllStudent();
        if(list.size()==0){
            System.out.println("查无信息，请稍后重试");
            return;
        }
        System.out.println("学号\t\t姓名\t\t年龄\t\t生日");
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println(student.getId()+"\t\t\t"+ student.getName()+"\t\t"+student.getAge()+"\t\t\t"+student.getBirthday());
        }
    }

    //添加学生
    public abstract void addStudent();
}
